#!/usr/bin/env python

import unittest
from volume import Volume
import util

class TestVolume(Volume, unittest.TestCase):
  def __init__(self, *args, **kwargs):
    unittest.TestCase.__init__(self, *args, **kwargs)
    Volume.__init__(self)

  def setUp(self):
    #print "setUp"
    pass

  def tearDown(self):
    #print "tearDown"
    pass

  def test_createVolume(self):
    name = "test_" + yoyoutil.getUniqueStr()
    zoneid = 1
    diskOfferingId = 3 
    response = self.createVolume(name, zoneid, diskOfferingId)
    self.assertEqual(response["name"], name)
    self.assertEqual(response["zoneid"],zoneid)
    self.assertEqual(response["diskofferingid"], diskOfferingId)

  def test_listVolumes(self):
    response = self.listVolumes()
    self.assertTrue(len(response) == 0 or response["count"]>0)

  def test_attachVolume(self):
    volumeid = 20
    virtualmachineid = 14
    response = self.attachVolume(volumeid, virtualmachineid)
    self.assertEqual(response["virtualmachineid"], virtualmachineid)

  def test_detachVolume(self):
    volumeid = 20
    response = self.detachVolume(volumeid)
    self.assertFalse(response.has_key("attached"))

  def test_deleteVolume(self):
    volumeid = 19
    response = self.deleteVolume(volumeid)
    self.assertEqual(response["success"], "true")

    

def get_suite():
  suite = unittest.TestSuite()
  #suite.addTest(TestVolume("test_createVolume"))
  #suite.addTest(TestVolume("test_listVolumes"))
  suite.addTest(TestVolume("test_attachVolume"))
  suite.addTest(TestVolume("test_detachVolume"))
  #suite.addTest(TestVolume("test_deleteVolume"))
  return suite

if __name__ == "__main__":
  suite = get_suite()
  runner = unittest.TextTestRunner()
  runner.run(suite)
